import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:fsharing/core/viewmodels/pages/ad_start_model.dart';
import 'package:fsharing/core/viewmodels/view_model.dart';
import 'package:fsharing/ui/widgets/count_down_skip.dart';
import 'package:provider/provider.dart';

class SplashPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider(
      create: (context) => AdStartModel(Provider.of(context, listen: false)),
      child: Scaffold(
        body: Column(
          children: <Widget>[
            Expanded(
              child: Stack(
                children: <Widget>[
                  Consumer<AdStartModel>(
                    builder: (context, model, child) {
                      switch (model.viewState) {
                        case ViewState.success:
                          return Container(
                            constraints: BoxConstraints.expand(),
                            child: CachedNetworkImage(
                              imageUrl: model.adUrl ?? '',
                              fit: BoxFit.fill,
                            ),
                          );
                        default:
                          return Container();
                      }
                    },
                  ),
                  Positioned(
                    top: 48,
                    right: 24,
                    child: CountDownSkip(
                      function: () => Navigator.of(context).pushReplacementNamed('/main'),
                    ),
                  ),
                ],
              ),
            ),
            Container(
              alignment: Alignment.center,
              decoration: BoxDecoration(
                color: Colors.white,
              ),
              height: 100,
              child: Image.asset('assets/images/splash_img_logo.png', width: 200),
            )
          ],
        ),
      ),
    );
  }
}
